﻿using System;
using System.Collections.Generic;
using System.Text;
using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;
using YouHP.Model.Group;

namespace YouHP.Pages.Ajax
{
    public class ShareBBSTopic : BasePage
    {
        protected StringBuilder sb = new StringBuilder();

        protected override void ShowPage()
        {

            base.ShowPage();
            if (ErrorCount > 0) return;

            int tid = RequestTools.GetQueryInt("tid", 0);
            if (tid <= 0) return;
            TopicInfo topicdata = TopicBLL.Instance.GetTopicInfo(tid);

            string msg = RequestTools.GetQueryString("message");

            //添加动态
            UserActionInfo info = new UserActionInfo();
            info.UserId = UserData.Id;
            info.UserName = UserData.UserName;
            info.ActionTime = DateTime.Now;
            info.ActionType = Constants.ACTION_SHARE;
            info.ActionContent = "分享了帖子\"<a href=\"" + this.GetUrl("/BBS/Topic.aspx?gid=" + topicdata.Groupid + "&tid=" + topicdata.Id) + "\"target=\"_blank\">" + topicdata.Title + "</a>\"";
            if (msg != "")
            {
                info.ActionContent += "&nbsp;理由是" + "\"<font style=\"font-weight:bold;\">" + msg + "</font>\"";
            }
            bool succ = UserActionBLL.Instance.AddUserAction(info);

            if (succ)
            {
                sb.Append("分享成功！");
            }
            else
            {
                sb.Append("系统出现问题，操作失败！");
            }

            ResponseXML(sb);
            return;

        }

        protected void ResponseXML(StringBuilder sb)
        {
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.ContentType = "Text/html";
            System.Web.HttpContext.Current.Response.Expires = 0;

            System.Web.HttpContext.Current.Response.Write(sb.ToString());
            System.Web.HttpContext.Current.Response.End();
        }

    }
}
